package com.mashiro.system.controller;

import com.mashiro.common.annotation.Log;
import com.mashiro.common.core.controller.BaseController;
import com.mashiro.common.core.domain.AjaxResult;
import com.mashiro.common.core.page.TableDataInfo;
import com.mashiro.common.enums.BusinessType;
import com.mashiro.common.utils.poi.ExcelUtil;
import com.mashiro.system.domain.MoeContractual;
import com.mashiro.system.service.IMoeContractualService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 合同Controller
 *
 * @author mashiro
 * @date 2023-04-14
 */
@RestController
@RequestMapping("/system/contractual")
public class MoeContractualController extends BaseController {
    @Resource
    private IMoeContractualService moeContractualService;

    /**
     * 查询合同列表
     */
    @PreAuthorize("@ss.hasPermi('system:contractual:list')")
    @GetMapping("/list")
    public TableDataInfo list(MoeContractual moeContractual) {
        startPage();
        List<MoeContractual> list = moeContractualService.selectMoeContractualList(moeContractual);
        return getDataTable(list);
    }

    /**
     * 导出合同列表
     */
    @PreAuthorize("@ss.hasPermi('system:contractual:export')")
    @Log(title = "合同", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MoeContractual moeContractual) {
        List<MoeContractual> list = moeContractualService.selectMoeContractualList(moeContractual);
        ExcelUtil<MoeContractual> util = new ExcelUtil<MoeContractual>(MoeContractual.class);
        util.exportExcel(response, list, "合同数据");
    }

    /**
     * 获取合同详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:contractual:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(moeContractualService.selectMoeContractualById(id));
    }

    /**
     * 新增合同
     */
    @PreAuthorize("@ss.hasPermi('system:contractual:add')")
    @Log(title = "合同", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MoeContractual moeContractual) {
        return toAjax(moeContractualService.insertMoeContractual(moeContractual));
    }

    /**
     * 修改合同
     */
    @PreAuthorize("@ss.hasPermi('system:contractual:edit')")
    @Log(title = "合同", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MoeContractual moeContractual) {
        return toAjax(moeContractualService.updateMoeContractual(moeContractual));
    }

    /**
     * 删除合同
     */
    @PreAuthorize("@ss.hasPermi('system:contractual:remove')")
    @Log(title = "合同", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(moeContractualService.deleteMoeContractualByIds(ids));
    }
}
